package cn.com.tomato.service;

import java.util.Date;
import java.util.List;

import cn.com.tomato.controller.domain.todoSet.ToDoVo;
import cn.com.tomato.mapper.FocusMapper;
import cn.com.tomato.mapper.TodoMapper;
import cn.com.tomato.model.Focus;
import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-08-16
 */
@Service
public class FocusService
{
    @Autowired
    private FocusMapper focusMapper;

    @Autowired
    private TodoMapper todoMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    public Focus selectFocusById(Long id)
    {
        return focusMapper.selectFocusById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param tocus 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    public List<Focus> selectFocusList(Focus tocus)
    {
        List<Focus> foci = focusMapper.selectFocusList(tocus);
        for (Focus focus : foci) {
            focus.setName(todoMapper.selectTodoById(focus.getTid()).getName());
        }
        return foci;
    }

    public List<Date> selectStartDay(Focus tocus)
    {
        return focusMapper.selectStartDay(tocus);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param tFocus 【请填写功能名称】
     * @return 结果
     */
    public Long insertFocus(Long tid, ToDoVo toDoVo) {
        Focus focus = new Focus();
        focus.setTid(tid);
        focus.setDuration(toDoVo.getTimeDuration());
        focus.setStatus(toDoVo.getStatus());
        focus.setStart(new Date());
        focus.setEnd(DateUtil.offsetMinute(focus.getStart(), toDoVo.getTimeDuration()));
        focus.setReason(toDoVo.getReason());
        focusMapper.insertFocus(focus);
        return focus.getId();
    }



    /**
     * 修改【请填写功能名称】
     * 
     * @param tFocus 【请填写功能名称】
     * @return 结果
     */
    public int updateFocus(Focus tFocus)
    {
        return focusMapper.updateFocus(tFocus);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    public int deleteFocusByIds(Long[] ids)
    {
        return focusMapper.deleteFocusByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    public int deleteFocusById(Long id)
    {
        return focusMapper.deleteFocusById(id);
    }
}